<?php

namespace App\Containers\AppSection\File\Actions;

use App\Containers\AppSection\File\Models\File;
use App\Containers\AppSection\File\Tasks\CreateFileTask;
use App\Containers\AppSection\File\UI\API\Requests\CreateFileRequest;
use App\Containers\AppSection\Log\Tasks\CreateLogTask;
use App\Ship\Cryptopro\CryptoHelper;
use App\Ship\Parents\Actions\Action;

class CreateFileAction extends Action
{
    public function run(CreateFileRequest $request): File
    {
        $file = app(CreateFileTask::class)->run(
            $request->file,
            $request->file_type,
            $request->profile()->id,
            $request->getInputByKey('project_id')
        );

        app(CreateLogTask::class)->run($request->profile()->id, "Файл №{$file->id} загружен", 'document');

        return $file;
    }
}
